﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册</title>
<link rel="stylesheet" href='css/style.css' type="text/css">
</head>
<script type="text/javascript" src="js/WdatePicker.js"></script>
<script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/sha1.js'></script>
<script type='text/javascript' src='js/public.js'></script>
<script type="text/javascript">
	
var code; 
	
	function login() {

		var userId = document.getElementById("userId").value;
		var inputCode = document.getElementById("htmlcode1").value;
		var userPwd = hex_sha1(document.getElementById("userPwd").value);
		var userp = document.getElementById("userPwd").value;
		var userPwd1 = document.getElementById("userPwd1").value;
		var enterYear = document.getElementById("enterYear").value;
		var userName = document.getElementById("userName").value;
		var major = document.getElementById("major").value;
		if (userId == "" || userp == "" || userPwd1 == "" || enterYear == ""
				|| userName == "" || major == "") {
			alert("请将信息输入完整！");
		} else if (inputCode=="") {
			alert("请输入验证码！");
			 createCode();
		}
		else if(inputCode != code){
			 alert("验证码输入错误！");
			   createCode();
		} 
		else if (check_validate1(userId)) {
			alert("学号必须是数字！");
		} else if (userp == userPwd1) {

			var params = "userId=" + encodeURIComponent(userId) + "&userPwd=" + encodeURIComponent(userPwd);

			new Ajax.Request("json/register", {
				method : "post",
				parameters : params,
				onComplete : function(request) {

					var res = request.responseText.evalJSON();
					
					if (res["result"]["flag"] == "true") {
						test();

					} else {
						alert("失败，请确认学号没有被注册,可联系团委办公室解决");
					}
				},
				asynchronous : true
			});
		} else {
			alert("两次输入密码不一致");
		}
	}

	function test() {

		var enterYear = document.getElementById("enterYear").value;
		var userName = document.getElementById("userName").value;
		var major = document.getElementById("major").value;
		var userclass = document.getElementById("userclass").value;
		
		var params = "User_keyName=userName&User_keyName=enterYear&User_keyName=major&User_keyName=userclass&User_keyName=privilegeToCreateLecture&User_keyValue="
				+ encodeURIComponent(userName)
				+ "&User_keyValue="
				+ encodeURIComponent(enterYear)
				+ "&User_keyValue="
				+ encodeURIComponent(major)
				+ "&User_keyValue="
				+ encodeURIComponent(userclass)
				+ "&User_keyValue="
				+ encodeURIComponent("0");
		
		new Ajax.Request("json/addUser_key", {
			method : "post",
			parameters : params,
			onComplete : function(request) {

				var res = request.responseText.evalJSON();
			
				if (res["result"]["flag"] == "true") {
					alert("成功注册");
					window.location.href = "login.html"

				} else
					alert("失败，请确认学号没有被注册");
			},
			asynchronous : true
		});
	}
	function createCode()   
	{    
	  code = "";  
	  var codeLength = 4;
	  var checkCode = document.getElementById("htmlcode2");  
	  var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符，当然也可以用中文的  
	     
	  for(var i=0;i<codeLength;i++)  
	  {    
	     
	  var charIndex = Math.floor(Math.random()*36);  
	  code +=selectChar[charIndex];          
	    
	  }  
	 
	  if(checkCode)  
	  {  
	   
	    checkCode.value = code;
	  
	  }  
	    
	} 

</script>
<body onload="online()">

	<div id="header">

		<div id="nav">
			<ul
				style="float: left; padding: 0 20px; text-align: center; line-height: 50px;">
				<li style="float: left; font-size: 28px">经管院学术讲坛事务系统</li>
			</ul>
			<ul class="horizon">

				<li class="login">
					<ul class="vertical">
						<li class="userInfo"><a>&nbsp;欢迎使用</a></li>

					</ul>
				</li>

			</ul>
		</div>




	</div>
	<div id="main">
		<div
			style="width: 21%; height: 660px; border-right: 3px #660033 solid; float: left; background-color: rgb(242, 247, 252);"></div>
		<div style="width: 78%; font-size: 22px; float: right">
			<div style="margin-top: 80px; margin-left: 250px; height: 500px">
				<form method="post" style="font-size: 18px">
					学号:<br> <input name="userId" size="30" id="userId"
						style="height: 25px;background:none; border:1px solid #CCC"><br> 密码:<br> <input
						type="password" id="userPwd" name="userPwd" size="30"
						style="height: 25px;background:none; border:1px solid #CCC"><br> 确认密码:<br> <input
						type="password" id="userPwd1" name="userPwd1" size="30"
						style="height: 25px;background:none; border:1px solid #CCC"><br> 姓名:<br> <input
						name="userName" size="30" id="userName" style="height: 25px;background:none; border:1px solid #CCC"><br>

					入学年份:<br> <input name="enterYear" size="30" id="enterYear"
						onclick="WdatePicker({dateFmt:'yyyy'})" style="height: 25px;background:none; border:1px solid #CCC"><br>
					专业:<br> <select name="major" id="major"
						style="height: 25px;background:none; width:250px; border:1px solid #CCC">
						<option value="林经">林经</option>
							<option value="会计">会计</option>
							<option value="统计">统计</option>
							<option value="国贸">国贸</option>
							<option value="工商">工商</option>
							<option value="金融">金融</option>
							<option value="物业">物业</option>
							<option value="人资">人资</option>
							<option value="信管">信管</option>
							<option value="电商">电商</option>
							<option value="营销">营销</option>
							<option value="梁希">梁希</option>
					</select><br> 班级:<br> <select name="userclass" id="userclass"
						style="height: 25px; width:250px;background:none; border:1px solid #CCC">
						<option value="1">1班</option>
						<option value="2">2班</option>
						<option value="3">3班</option>
						<option value="4">4班</option>
					
					</select><br>验证码：<br><input id="htmlcode1" onclick="createCode()" style="height: 25px;background:none;width: 250px; border:1px solid #CCC"><input
								id="htmlcode2" style="width: 80px; margin-left:10px;height: 25px; background: gray; border: 0;"
								onClick="createCode()" readonly="readonly" /> <a href="#"
								onClick="createCode()" style="font-size: 12px">看不清?</a><br><br> <input type="button" value="注册"
						onclick="login()"
						style="border:1px solid; border-color:#CCC; height: 28px; width: 70px; font-size: 22px;">
				</form>

			</div>
			<div style="font-size: 14px; margin-left: 100px;">
				<span id="online">当前在线人数:</span> <span style="margin-left: 150px">Copyright
					&copy; 2013 经济管理学院 北京市海淀区清华东路35号 邮编：100083</span>
			</div>
		</div>
	</div>

</body>
</html>
